package com.canplay.screen.utils

import android.os.Handler
import android.os.Looper

/**
 * @Description:Thread工具类
 */
object ThreadUtils {

    private val mainHandler: Handler = Handler(Looper.getMainLooper())

    fun isMainThread(): Boolean {
        return Looper.myLooper() == Looper.getMainLooper()
    }

    fun getMainHandler(): Handler {
        return mainHandler
    }

    fun runOnUiThread(runnable: Runnable) {
        if (isMainThread()) {
            runnable.run()
        } else {
            mainHandler.post(runnable)
        }

    }

    fun runOnUiThreadDelay(runnable: Runnable, delayMillis: Long) {
        mainHandler.postDelayed(runnable, delayMillis)
    }
}